﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TextBoxAdapter.cs" company="">
//   
// </copyright>
// <summary>
//   The text box adapter.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Adapters
{
    using System;
    using System.Windows.Forms;

    using Libium.Views;

    /// <summary>
    /// The text box adapter.
    /// </summary>
    public class TextBoxAdapter : ControlAdapter<TextBox>, ITextEditView
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TextBoxAdapter"/> class.
        /// </summary>
        /// <param name="textBox">
        /// The text box.
        /// </param>
        public TextBoxAdapter(TextBox textBox)
            : base(textBox)
        {
            Control.TextChanged += OnTextChanged;
            DropHandler.AddControl(Control);
        }

        #endregion

        #region Public Events

        /// <summary>
        /// The text changed.
        /// </summary>
        public event Action<ITextEditView> TextChanged;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets a value indicating whether read only.
        /// </summary>
        public override bool ReadOnly
        {
            get
            {
                return Control.ReadOnly;
            }

            set
            {
                Control.ReadOnly = value;
            }
        }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        public string Text
        {
            get
            {
                return Control.Text;
            }

            set
            {
                Control.Text = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The on text changed.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected virtual void OnTextChanged(object source, EventArgs e)
        {
            if (TextChanged != null)
            {
                TextChanged(this);
            }
        }

        #endregion
    }
}